/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Rdf;

import NodeManager.Node;
import com.hp.hpl.jena.rdf.model.Bag;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Sean
 */
public class RdfWriter {

    public static void AddNode(Model model, Node node) {
        if (model == null) {
            throw new IllegalArgumentException("Model cannot be null");
        }
        if (node == null) {
            throw new IllegalArgumentException("Node cannot be null");
        }

        Resource nodeResource = model.createResource(Global.Data.BaseURI + node.NodeName);
        nodeResource.addProperty(RdfCommon.CreateProperty("NodeLocation"), node.GetLocation());

    }

    public static void AddFile(Model model, File file, Node node) {

        if (model == null) {
            throw new IllegalArgumentException("Model cannot be null");
        }

        if (file == null) {
            throw new IllegalArgumentException("File cannot be null");
        }

        if (node == null) {
            throw new IllegalArgumentException("Node cannot be null");
        }

        String myFileURI = Global.Data.BaseURI + file.getName();

        // create the resource
        //   and add the properties cascading style
        Resource myFile = model.createResource(myFileURI);

        myFile.addProperty(RdfCommon.CreateProperty("Filename"), file.getName());

          Date lastMod = new Date(file.lastModified());

          SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmm:ss");

          String lastModAsStr =  sdf.format(lastMod);


        myFile.addProperty(RdfCommon.CreateProperty("LastModified"), lastModAsStr);

        Resource myNodes = model.createResource(myFileURI + "/Nodes");
        myFile.addProperty(RdfCommon.CreateProperty("Nodes"), myNodes);

        Bag NodesBag = model.createBag(myFileURI + "/Nodes");
        NodesBag.add(node.NodeName);

    }

}
